package org.to_zero.ssm.sdm.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.to_zero.ssm.sdm.entity.User;
import org.to_zero.ssm.sdm.entity.vo.ResponseEntity;
import org.to_zero.ssm.sdm.mapper.UserMapper;
import org.to_zero.ssm.sdm.service.UserService;
import org.to_zero.ssm.sdm.util.Toolkit;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;


    @Override
    public ResponseEntity findUserByCondition(User user) {
        return ResponseEntity.success(userMapper.findUserByCondition(user));
    }

    @Override
    public ResponseEntity update(User user) {
        int flg = Toolkit.nonNull(user.getId()) ? userMapper.updateByPrimaryKeySelective(user) : userMapper.insertSelective(user);
        return flg > 0 ? ResponseEntity.success("更新成功") : ResponseEntity.error("出了一点问题o(╥﹏╥)o");
    }

    @Override
    public ResponseEntity deleteById(Integer id) {
        int flg = userMapper.deleteByPrimaryKey(id);
        return flg > 0 ? ResponseEntity.success("删除成功") : ResponseEntity.error("出了一点问题o(╥﹏╥)o");
    }

    @Override
    public ResponseEntity deleteByIds(Integer[] ids) {
        int flg = userMapper.deleteByPrimaryKeys(ids);
        return flg > 0 ? ResponseEntity.success("批量删除成功") : ResponseEntity.error("出了一点问题o(╥﹏╥)o");
    }
}
